<template>
	<div class="user">
		<commonUserinfo :userInfoData="{userItemIndex:itemIndex,userLeftHeight:userLeftHeight,$parent:$parent}">
			<div id="onlineFeedback" class="user_main_right f_left text_center">
				<div class="user_userInfo modify_pwd color666">
					<form ref="form" :model="form">
						<dl>
							<dt class="f_left">反馈的内容：</dt>
							<dd class="f_left">
								<textarea class="online_feedback_textarea color666" type="text" cols="10" onkeyup="this.value=this.value.substring(0, 200)"
								 placeholder="最多可输入200字！" v-model.trim="form.text"></textarea>
							</dd>
						</dl>
						<dl>
							<dt class="f_left">手机验证码：</dt>
							<dd class="f_left">
								<input v-model.trim="form.code" class="modify_code" type="text">
								<input type="button" :value="verifyCode" :disabled="disabled" @click="getVerifyCode" class="modify_getCode_btn text_center">
							</dd>
						</dl>
						<a class="modify_sure_btn" @click="onSubmitted(form)">提交</a>
					</form>
				</div>
			</div>
		</commonUserinfo>
	</div>
</template>

<script>
	import commonUserinfo from '../../components/c_userinfo.vue'
	export default {
		name: "feedback",
		data: function() {
			return {
				itemIndex: 7,
				userLeftHeight: '',
				verifyCode: "获取短信验证码",
				disabled: false,
				form: {
					text: "",
					code: "",
					v_token:""
				}
			}
		},
		mounted: function() {},
		methods: {
			getVerifyCode: function() {
				var that = this;
				this.common.post(this.api.getVerifyCodeFeedBack, {
				}, function(data) {
					that.form.v_token=data.resultMap;
					that.setInter();
				}, function(error) {
					that.$message.error(error.resultMsg);
				});

			},
			setInter: function() {
				var that = this;
				var countDown = 60;
				clearInterval(timer);
				var timer = setInterval(function() {
					countDown--;
					that.verifyCode = "短信已发送（" + countDown + "）";
					that.disabled = true;
					if (countDown < 1) {
						clearInterval(timer);
						that.verifyCode = "获取短信验证码";
						that.disabled = false;
					}
				}, 1000);
			},
			onSubmitted: function(dataForm) {
				var that = this;
				if (dataForm.text.trim() == "") {
					this.$message.error('请填写您要反馈的内容！');
					return;
				}
				if (dataForm.code.trim() == "") {
					this.$message.error('请输入验证码！');
					return;
				}
				this.common.post(this.api.feedback, dataForm, function(data) {
					that.$message.success('提交成功！')
					that.common.toPage('/user_info');
				}, function(error) {
					// alert(JSON.stringify(error.resultMsg))
					that.$message.error(error.resultMsg);
				});
			}
		},
		components: {
			commonUserinfo
		}
	}
</script>

<style>

</style>
